<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
</head>
<body>
<div id="app">
  <button @click="type=0">默认</button>
  <button @click="type=1">升序</button>
  <button @click="type=2">降序</button>
  <input type="text" v-model="search">
  <hr>
  <ul>
    <li v-for="item in searchRes" :key="item.id">name:{{item.name}}---age:{{item.age}}</li>
  </ul>
</div>
<script>
  Vue.config.productionTip = false
  const vm = new Vue({
    el: '#app',
    data() {
      return {
        search:'',
        persons:[
          {id:'001',name:'周杰伦',age:18},
          {id:'002',name:'陈冠希',age:8},
          {id:'003',name:'华晨宇',age:28},
          {id:'004',name:'张杰',age:30},
          {id:'005',name:'张靓颖',age:23},
          {id:'006',name:'周深',age:51}
        ],
        type:0
      }
    },
    computed:{
      searchRes(){
        const temp = this.persons.filter(item=>{
          return item.name.includes(this.search)
        })
        switch (this.type){
          case 1:
            return temp.sort((a,b)=>a.age-b.age)
          case 2:
            return temp.sort((a,b)=>b.age-a.age)
          default:
            return temp
        }
      }
    }
  })
</script>
</body>
</html>